package guicommon.gui;

import guicommon.Body;
import guicommon.Header;
import guicommon.Message;
import java.nio.CharBuffer;

public class UpdateMessage extends Message {

    public static final Integer ID = 5;

    public static final String CONTROL_ID = "ControlId";
    public static final String KEY = "Key";
    public static final String VALUE = "Value";

    UpdateMessage(Header header, CharBuffer buffer) {
        super(header, buffer);
    }

    public UpdateMessage() {
        super(Header.FromType(UpdateMessage.class, ID));
    }

    @Override
    protected void ParseBody(CharBuffer charBuffer) {
        String allPropertiesString = charBuffer.toString();
        String[] properties = allPropertiesString.split(Body.SOH);
        for (String current : properties) {
            String[] pair = current.split("=");
            if (pair.length != 1) {
                AddParseBodyField(pair[0], pair[1]);
            }
        }
    }

    public void SetUpdatedField(String id, String key, String value) {
        SetBodyField(CONTROL_ID, id);
        SetBodyField(KEY, key);
        SetBodyField(VALUE, value);
    }

    public String GetId() {
        return GetBodyField(CONTROL_ID);
    }

    public String GetKey() {
        return GetBodyField(KEY);
    }

    public String GetValue() {
        return GetBodyField(VALUE);
    }
}
